﻿using System.Text.RegularExpressions;

namespace BarrageGameAssistant.Core.Utils
{
    public class RegexUtils
    {
        /// <summary>
        /// 提取汉字
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string GetChinese(string input)
        {
            string result = string.Empty;
            Regex regex = new(@"[\u4e00-\u9fa5]+"); // 定义正则表达式，匹配所有连续的汉字

            MatchCollection matches = regex.Matches(input); // 获取所有匹配项

            foreach (Match match in matches)
            {
                result += match.Value;
            }
            return result;
        }

        /// <summary>
        /// 提取英文
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string GetEnglish(string input)
        {
            string result = string.Empty;
            Regex regex = new(@"[a-zA-Z]+"); // 定义正则表达式，匹配所有连续的汉字

            MatchCollection matches = regex.Matches(input); // 获取所有匹配项

            foreach (Match match in matches)
            {
                result += match.Value;
            }
            return result;
        }

        /// <summary>
        /// 提取数字和小数点
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string GetDigit(string input)
        {
            string result = string.Empty;
            Regex regex = new(@"\d+(\.\d+)?"); // 定义正则表达式，匹配所有连续的汉字

            MatchCollection matches = regex.Matches(input); // 获取所有匹配项

            foreach (Match match in matches)
            {
                result += match.Value;
            }
            return result;
        }
    }
}
